package top.bulk.encrypt.strategy;

import cn.hutool.core.io.resource.ClassPathResource;
import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.nio.charset.Charset;

/**
 * 配置参数
 *
 * @author 散装java
 * @date 2024-07-26
 */
@Data
@Slf4j
@ConfigurationProperties(prefix = "bulk.crypto")
public class CryptoProperties {
    private String aesKey;

    private String rsaPublicKey;
    private String rsaPrivateKey;

    @SneakyThrows
    public void setRsaPublicKey(String rsaPublicKey) {
        // 根据路径 rsaPublicKey 获取公钥
        ClassPathResource resource = new ClassPathResource(rsaPublicKey);

        // 读取 resource 中的内容到 string
        this.rsaPublicKey = resource.readStr(Charset.defaultCharset());
    }

    public void setRsaPrivateKey(String rsaPrivateKey) {
        ClassPathResource resource = new ClassPathResource(rsaPrivateKey);
        this.rsaPrivateKey = resource.readStr(Charset.defaultCharset());
    }
}
